/**
    ATClab - scriptable Air Traffic Control simulations.
    Copyright (C) 2010 openatclab@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/

#ifndef __PARALLEL_PORT_IO_HDR__ 
#define __PARALLEL_PORT_IO_HDR__


#include <qobject.h>


//void  _stdcall Out32( short PortAddress, short data );


namespace plugin {

    //
    // plugin::ParallelPortIO
    //

    class ParallelPortIO : public QObject {
		Q_OBJECT

	public:

        enum DataBus {
                CLR     = 0x0000,
                D0      = 0x0001,
                D1      = 0x0002,
                D3      = 0x0004,
                D4      = 0x0008,
                D5      = 0x0010,
                D6      = 0x0020,
                D7      = 0x0040,
                SET     = 0x00FF
            };

		friend class ParallelPortIOConnector;

	private:
		const static short ADDRESS;

    public:
        ParallelPortIO( QObject *parent ) 
				: QObject( parent), _address(ADDRESS), _data( CLR ) 
		{
			write();
		}
        ~ParallelPortIO() {}

	public:
		void write() { /*Out32( _address, _data );*/ }

    public:
		void set_address( short address ) { _address = address; }

	private:
		short _address;
		short _data;
	};


	//
	//
	//
	class ParallelPortIOConnector : public QObject {
		Q_OBJECT
	public:
		ParallelPortIOConnector( ParallelPortIO *port, ParallelPortIO::DataBus channel ) 
				: QObject( port ), _port( port), _channel( channel ) {};
		~ParallelPortIOConnector() {};
	public slots:
		void set_on() { _port->_data |= _channel; _port->write(); }
		void set_off() { _port->_data &= ~_channel; _port->write(); }
	private:
		ParallelPortIO			*_port;
		ParallelPortIO::DataBus	 _channel;
	};


};

#endif
